﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Pigg.Contracts;
using Pigg.Model;
using System.Data.Entity;

namespace Pigg.Data
{
    public class ModelReader : IModelReader 
    {
        private readonly PiggDbContext _db;

        public ModelReader(IDatabaseFactory databaseFactory)
        {
            _db = databaseFactory.Get() as PiggDbContext;
        }

        public ContentPage GetPage()
        {
            throw new NotImplementedException();
        }

        public ContentPage GetPage(string route)
        {
            return _db.ContentPages.FirstOrDefault(c => c.Url == route);
        }

        public MenuContainer GetMenu(string cultureCode, string menuName)
        {
            return _db.MenuContainers
                .Include(m => m.MenuItems)
                .FirstOrDefault(c => c.CultureCode == cultureCode && c.Name == menuName);
        }
    }
}
